package com.agileboot.domain.airport.inspection.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Business;
import com.agileboot.domain.airport.inspection.db.SirInspectionEntity;
import com.agileboot.domain.airport.inspection.db.SirInspectionService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @author valarchie
 */
@Component
@RequiredArgsConstructor
public class SirInspectionModelFactory {

    @Qualifier("sirInspectionServiceImpl")
    private final SirInspectionService inspectionService;

    public SirInspectionModel loadById(Long inspectionId) {
        SirInspectionEntity byId = inspectionService.getById(inspectionId);
        if (byId == null) {
            throw new ApiException(Business.COMMON_OBJECT_NOT_FOUND, inspectionId, "检查计划");
        }
        return new SirInspectionModel(byId, inspectionService);
    }

    public SirInspectionModel create() {
        return new SirInspectionModel(inspectionService);
    }

}